﻿using System;
using System.ComponentModel;

namespace YArchitech.HCLoad.Query
{
	public class PropertyGridAttrituteDescriptor : PropertyDescriptor
	{
		public PropertyGridAttrituteDescriptor(PropertyGridAttritute prop, Attribute[] attrs) : base(prop.Name, attrs)
		{
			this.theProp = prop;
		}

		public override bool CanResetValue(object component)
		{
			return false;
		}

		public override Type ComponentType
		{
			get
			{
				return base.GetType();
			}
		}

		public override object GetValue(object component)
		{
			return this.theProp.Value;
		}

		public override string Category
		{
			get
			{
				return this.theProp.Category;
			}
		}

		public override string Description
		{
			get
			{
				return this.theProp.Description;
			}
		}

		public override bool IsReadOnly
		{
			get
			{
				return false;
			}
		}

		public override Type PropertyType
		{
			get
			{
				if (this.theProp.Value != null)
				{
					return this.theProp.Value.GetType();
				}
				return typeof(string);
			}
		}

		public override void ResetValue(object component)
		{
		}

		public override void SetValue(object component, object value)
		{
		}

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		private PropertyGridAttritute theProp;
	}
}
